package 
{
	import fl.controls.TextArea;
	
	import flare.animate.Easing;
	import flare.display.TextSprite;
	
	import flash.display.*;
	import flash.events.*;
	
	[SWF(backgroundColor="#FFFFFF", frameRate="20", width="1000", height="700")]
	public class CareerGPSDemo extends Sprite
	{
		private var careerSpace:CareerSpace;
		
		private var title:Title;
		
		private var inputText:DoubleInputText;
		
		private var debugText:TextSprite;
		
		public function CareerGPSDemo()
		{
			this.x = 5;  // offset a little
			this.y = 0;
			
			// central part, CareerSpace
			careerSpace = new CareerSpace();
			careerSpace.x = 0;
			careerSpace.y = 100;
			this.addChild(careerSpace);
			
			// title
			title = new Title();
			title.x = 0;
			title.y = 0;
			this.addChild(title);
			
			inputText = new DoubleInputText("Search Paths");
			inputText.x = 0;
			inputText.y = 35;
			this.addChild(inputText);
			this.addEventListener("Search Paths", onSearchPaths);
			this.addEventListener("SELECTED_PATH_FOUND", onFoundSelectedPath);
			
			// debug text
			debugText = new TextSprite();
			debugText.visible = true;
			this.addChild(debugText);
		}
		
		public function onSearchPaths(e:Event):void {
			// TODO to remove, for debug only
			//dispInfo(this.inputText.getTextContent().toString(), 500, 0);
			
			var input:Array = this.inputText.getTextContent();
			
			// determine if input starting point
			this.careerSpace.setStartingPoint(input[0]);
			
			// determine if input ending point
			this.careerSpace.setEndignPoint(input[1]);
			
			// show stats panel for all paths with same starting point
			showPathStats();
		}
		
		private function showPathStats():void {
			var infoPanel:Sprite = new Sprite();
			infoPanel.x = 800;
			infoPanel.y = 100;
			infoPanel.graphics.beginFill(0xffffff);
			infoPanel.graphics.drawRect(0, 0, 200, 600);
			infoPanel.graphics.endFill();
			this.addChild(infoPanel);
			
			var stats:Array = this.careerSpace.getPathStats();
			var ox:int = 30;
			var oy:int = 180;
			var stepY:int = 65;
			for (var i:int = 0; i < stats.length; i++) {
				var ts1:TextSprite = new TextSprite();
				ts1.text = stats[i][1] + " people";
				ts1.x = ox;
				ts1.y = oy + i * stepY;
				ts1.color = 0x009999;
				ts1.size = 30;
				ts1.underline = true;
				infoPanel.addChild(ts1);
				
				var ts2:TextSprite = new TextSprite();
				ts2.text = stats[i][0];
				ts2.x = ox;
				ts2.y = oy + i * stepY + 30;
				ts2.size = 15;
				infoPanel.addChild(ts2);
			}
			
			var ts3:TextSprite = new TextSprite("More paths...");
			ts3.x = 85;
			ts3.y = oy + stepY * stats.length;
			ts3.size = 15;
			ts3.underline = true;
			ts3.color = 0x009999;
			infoPanel.addChild(ts3);
		}
		
		public function onFoundSelectedPath(e:Event):void {
			var path:CareerPath = careerSpace.getSelectedPath();
			
			var infoPanel:Sprite = new Sprite();
			infoPanel.x = 800;
			infoPanel.y = 100;
			infoPanel.graphics.beginFill(0xffffff);
			infoPanel.graphics.drawRect(0, 0, 200, 600);
			infoPanel.graphics.endFill();
			this.addChild(infoPanel);
			
			var ts1:TextSprite = new TextSprite("Bookmark it\n\nPublish it");
			ts1.x = 30;
			ts1.y = 180;
			ts1.size = 30;
			ts1.underline = true;
			ts1.color = 0x009999;
			infoPanel.addChild(ts1);
			
			var ts2:TextSprite = new TextSprite("More options...");
			ts2.x = 85;
			ts2.y = 320;
			ts2.size = 15;
			ts2.underline = true;
			ts2.color = 0x009999;
			infoPanel.addChild(ts2);
			
			/*
			dispInfo(path.arrayJob[0].getPosition() + "\t" +
				     path.arrayJob[0].getField() + "\n" +
					 path.arrayJob[1].getPosition() + "\t" +
					 path.arrayJob[1].getField() + "\n" +
					 path.arrayJob[2].getPosition() + "\t" +
					 path.arrayJob[2].getField() + "\n",
					 800, 300);
			*/
		}
		
		public function dispInfo(str:String, x:int, y:int):void {
			debugText.text = str;
			debugText.x = x;
			debugText.y = y;
		}
		
	}
	
}
